import Component from '@glimmer/component';
import { service } from '@ember/service';
import { tracked } from '@glimmer/tracking';

export default class ConfigComponent extends Component {
  @service call;
  @tracked text = '';

  constructor() {
    super(...arguments);
    this.call.getCached('/api/config/' + this.args.key).then((res) => {
      if (res.success) {
        if (this.args.index) {
          var data = JSON.parse(res.data.value);
          const result = data.find((item) => item.id === this.args.index);
          this.text = result.name;
        } else {
          this.text = res.data.value;
        }
      } else {
        console.log('获取config失败,key=' + this.args.key);
      }
    });
  }
}
